<?php
class GoodsVo extends SzAbstractMySqlVo
{

    private $userId;
    private $decorId;
    private $itemDefId;
    private $count;
    private $flower;
    private $wrapperId;
    private $gifts;
    private $harvestTime;
    private $isSell;
    private $rewards;
    private $level;

    /**
     * Initialize GoodsVo.
     *
     * @param $userId
     * @param $decorId
     * @param $itemDefId
     * @param $count
     * @param $flower
     * @param $wrapperId
     * @param $gifts
     * @param $harvestTime
     * @param $isSell
     * @param $rewards
     * @param $level
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return GoodsVo
     */
    public function __construct($userId, $decorId, $itemDefId, $count, $flower, $wrapperId, $gifts, $harvestTime, $isSell, $rewards, $level = 1, $isInsert = false) {
        $this->userId = $userId;
        $this->decorId = $decorId;
        $this->itemDefId = $itemDefId;
        $this->count = $count;
        $this->flower = $flower;
        $this->wrapperId = $wrapperId;
        $this->gifts = json_decode($gifts, true);
        $this->harvestTime = $harvestTime;
        $this->isSell = $isSell;
        $this->rewards = json_decode($rewards, true);
        $this->level = $level;

        $this->isInsert = $isInsert;
        $this->voClassName = 'GoodsVo';
        $this->ormName = 'Goods';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'decorId' => $this->getDecorId(),
            'itemDefId' => $this->getItemDefId(),
            'count' => $this->getCount(),
            'flower' => $this->getFlower(),
            'wrapperId' => $this->getWrapperId(),
            'gifts' => ($needEncode) ? $this->getGifts() : $this->getRawGifts(),
            'harvestTime' => $this->getHarvestTime(),
            'isSell' => $this->getIsSell(),
            'rewards' => ($needEncode) ? $this->getRewards() : $this->getRawRewards(),
            'level' => $this->getLevel(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'decorId' => $this->getDecorId(),
            'itemDefId' => $this->getItemDefId(),
            'count' => $this->getCount(),
            'flower' => $this->getFlower(),
            'wrapperId' => $this->getWrapperId(),
            'gifts' => ($needEncode) ? $this->getGifts() : $this->getRawGifts(),
            'harvestTime' => $this->getHarvestTime(),
            'isSell' => $this->getIsSell(),
            'rewards' => ($needEncode) ? $this->getRewards() : $this->getRawRewards(),
            'level' => $this->getLevel(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getDecorId(),
            $this->getItemDefId(),
            $this->getCount(),
            $this->getFlower(),
            $this->getWrapperId(),
            $this->getGifts(),
            $this->getHarvestTime(),
            $this->getIsSell(),
            $this->getRewards(),
            $this->getLevel(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getDecorId()
    {
        return $this->decorId;
    }

    public function setDecorId($val)
    {
        $this->saveColumnStatus(1, $this->decorId);
        $this->decorId = $val;
    }

    public function getItemDefId()
    {
        return $this->itemDefId;
    }

    public function setItemDefId($val)
    {
        $this->saveColumnStatus(2, $this->itemDefId);
        $this->itemDefId = $val;
    }

    public function getCount()
    {
        return $this->count;
    }

    public function setCount($val)
    {
        $this->saveColumnStatus(3, $this->count);
        $this->count = $val;
    }

    public function getFlower()
    {
        return $this->flower;
    }

    public function setFlower($val)
    {
        $this->saveColumnStatus(4, $this->flower);
        $this->flower = $val;
    }

    public function getWrapperId()
    {
        return $this->wrapperId;
    }

    public function setWrapperId($val)
    {
        $this->saveColumnStatus(5, $this->wrapperId);
        $this->wrapperId = $val;
    }

    public function getGifts()
    {
        return json_encode($this->gifts);
    }

    public function getRawGifts()
    {
        return $this->gifts;
    }

    public function setGifts($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 128) {
            SzLogger::get()->error('[GoodsVo] The length of column gifts exceed the limit, length / limit: ' . $encodedLength . ' / 128');
            throw new SzException(10522, array('GoodsVo', '128', $encodedLength));
        } else if ($encodedLength > 115) {
            SzLogger::get()->warn('[GoodsVo] The length of column gifts exceed the warning level, length / limit: ' . $encodedLength . ' / 128');
        }
        $this->saveColumnStatus(6, $this->gifts);
        $this->gifts = $val;
    }

    public function getHarvestTime()
    {
        return $this->harvestTime;
    }

    public function setHarvestTime($val)
    {
        $this->saveColumnStatus(7, $this->harvestTime);
        $this->harvestTime = $val;
    }

    public function getIsSell()
    {
        return $this->isSell;
    }

    public function setIsSell($val)
    {
        $this->saveColumnStatus(8, $this->isSell);
        $this->isSell = $val;
    }

    public function getRewards()
    {
        return json_encode($this->rewards);
    }

    public function getRawRewards()
    {
        return $this->rewards;
    }

    public function setRewards($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 128) {
            SzLogger::get()->error('[GoodsVo] The length of column rewards exceed the limit, length / limit: ' . $encodedLength . ' / 128');
            throw new SzException(10522, array('GoodsVo', '128', $encodedLength));
        } else if ($encodedLength > 115) {
            SzLogger::get()->warn('[GoodsVo] The length of column rewards exceed the warning level, length / limit: ' . $encodedLength . ' / 128');
        }
        $this->saveColumnStatus(9, $this->rewards);
        $this->rewards = $val;
    }

    public function updateCount($val)
    {
        $this->setCount($this->count + $val);
    }

    public function getLevel()
    {
        return $this->level;
    }

    public function setLevel($val)
    {
        $this->saveColumnStatus(10, $this->level);
        $this->level = $val;
    }

}